First, your application needs to create an instance of Chrome or Edge using the HttpWatch extension, as explained in the C# - Overview topic. Having done this, your application will contain references to Controller and Plugin objects.
The following discussion assumes that these object references are called control and plugin, respectively.
Before starting recording, you should decide whether to enable or disable HttpWatch filtering. The automation interface only allows you to enable or disable an existing filter. The filtering criteria itself can only be set up manually through the HttpWatch extension user interface.
If you do not specifically want to use a filter it is best to disable filtering in your application, as follows:
| Turn Off Filtering |
Copy Code
|
|---|---|
plugin.Log.EnableFilter(false);
|
|
Alternatively, to enable filtering, make the same call, but with the parameter set to true.
To make sure that you don't pick up traffic that was previously recorded in HttpWatch by a user or another automation program, you should clear the Log object that is associated with the Plugin. This can be done with the Plugin object's Clear method:
| Clear the HttpWatch Log |
Copy Code
|
|---|---|
plugin.Clear(); |
|
It may also be necessary to put the browser into a known state at the start of your test. Often this is achieved by clearing the browser cache and cookie database to emulate the state of the browser when a new visitor opens a web page. The extension object provides two methods, ClearCache and ClearAllCookies to perform these tasks.
To activate traffic logging, call the Plugin object's Record method:
| Start Recording |
Copy Code
|
|---|---|
plugin.Record(); |
|
Of course, nothing will be recorded by HttpWatch until the browser starts to access and interact with web pages.
In an automation program, there are two ways to drive the browser:
Option 2 is less powerful and flexible than the first option, but it provides a simple way to test that pages load correctly and to measure their performance.
The GotoURL method returns immediately without waiting for the page to load. Normally, you would want to wait for the page to load so that you could look at the traffic that it generated or the performance timings gathered by HttpWatch. To do this, call the Controller object's Wait method, passing the Plugin object reference and a timeout value in seconds (-1 waits forever):
| Loading a Page using HttpWatch |
Copy Code
|
|---|---|
string myUrl = "http://www.example.com/"; plugin.GotoURL(myUrl); control.Wait( plugin, -1 /* don't return until the page loads */ ); |
|
For more information about how the page load is detected please see the documentation for the IsLoadingPage property and the Wait method.
When you wish to stop recording HTTP traffic, call the Plugin object's Stop method:
| Stop Recording |
Copy Code
|
|---|---|
plugin.Stop(); |
|
At the end of your application, or earlier if appropriate, you should close the browser by calling the Plugin object's CloseBrowser method:
| Close the Browser |
Copy Code
|
|---|---|
plugin.CloseBrowser(); |
|